﻿/*******************************************************************************
* 
*Author         :  VN
*Description    :  网络发包缓存内存池
*Other          :  none
*Modify Record  :  none
*
*******************************************************************************/
using System.Collections.Generic;
using System.Collections;

namespace Network
{
    public class MsgInfoPool
    {
        static List<MsgInfo> m_list = new List<MsgInfo>();

        public static MsgInfo New(uint uSeqId, uint cmdID, byte[] msg, CMsgDelegate callback, int nRetryTimes, float fTimeout, bool bNeedRes)
        {
            MsgInfo info = null;
            if (m_list.Count > 0)
            {
                info = m_list[0];
                m_list.RemoveAt(0);
                info.Set(uSeqId, cmdID, msg, callback, nRetryTimes, fTimeout, bNeedRes);
            }
            else
            {
                info = new MsgInfo(uSeqId, cmdID, msg, callback, nRetryTimes, fTimeout, bNeedRes);
            }
            return info;
        }

        public static void Delete(MsgInfo info)
        {
            info.Reset();
            m_list.Add(info);
        }

        public static void Clear()
        {
            m_list.Clear();
        }
    }
}